// const express = require('express');
// var app = express();
// var cors = require('cors');
// app.use(cors({
//     origin:['http://localhost:8081'],
//     methods:['GET','POST'],
//     alloweHeaders:['Conten-Type', 'Authorization']
// }));
const express = require('express')
let route = express.Router()
var url = require('url');
let api = require('../controller/index');
const {connection} = require('../connect/connect');
const ct = require('../controller/ct');
const ad = require('../controller/advice');


route.post('/auth/register', api.register)  //注册
route.post('/auth/login', api.login)  //登录
route.get('/user', api.user)  //获取用户信息
route.post('/user', api.reviseUser)  //修改信息
route.get('/index', api.index) //主页资源
route.get('/auth/oss/token', api.uploadAvatar) //主页资源

route.get('/goods/:aid', api.goodsDetail)//商品详情
route.get('/goods', api.goods)//商品分类

route.get('/carts', api.carts)  //加入购物车
route.put('/carts/:aid', api.setCartsNum)  //更改购物车数量
route.post('/carts', api.addCarts)  //加入购物车
route.delete('/carts/:aid', api.removeCarts)  //移除购物车
route.post('/carts/checked', api.setCartsChecked)  //更改选中状态
// route.get('/carts/:aid', api.setCartsChecked)  //更改购物车数量

route.get('/collects', api.collects)  //获取收藏
route.post('/collects/goods/:aid', api.addCollects)  //添加收藏

route.get('/address', api.address)  //获取地址
route.post('/address', api.addAddress)  //获取地址
route.post('/address/:aid', api.updateAddress)  //更改地址
route.delete('/address/:aid', api.removeAddress)  //删除地址


route.post('/orders', api.orders)  //更改地址
route.get('/orders/preview', api.preview)  //获取地址


route.get('/getUser',api.getUser)
route.post('/insertUser',api.insertUser)

route.post('/insertCollect',api.insertCollect)//添加收藏


route.post('/addCart',ct.addCart)
route.get('/getCart',ct.getCart)
route.get('/deleteCart',ct.deleteCart)


route.post('/addOrder',ct.addOrder)//订单操作
route.get('/getOrder',ct.getOrder)
route.get('/getOrderDetail',ct.getOrderDetail)
route.get('/deleteOrder',ct.deleteOrder)

route.post('/addAdvice',ad.addAdvice)
route.get('/AdviceBook',ad.AdviceBook)

exports.route = route;